
// **************************************************************************
// Project : junior.prj
// File    : global.c
// Object  : definitions of global variables
// Author  : Ricky Hsu
// Date    : 820810
// **************************************************************************

// ---------------------------------------------------------------------------
//			 system related parameters
// ---------------------------------------------------------------------------

//BYTE	    palette_table[256][3]  // color values of RAMDAC
PALETTEENTRY  palette_table[256]    // color values of RAMDAC
   = { //	R     G     B	       R     G	   B	      R     G	  B	     R	   G	 B
   /*	0 */	0,    0,    0, 0,      0,    0, 0xAB, 0,      0, 0xAB,	  0, 0,      0, 0xAB, 0xAB, 0,
   /*	4 */ 0xAB,    0,    0, 0,   0xAB,    0, 0xAB, 0,   0xAB, 0x57,	  0, 0,   0xAB, 0xAB, 0xAB, 0,
   /*	8 */ 0x57, 0x57, 0x57, 0,   0x57, 0x57, 0xFF, 0,   0x57, 0xFF, 0x57, 0,   0x57, 0xFF, 0xFF, 0,
   /*  12 */ 0xFF, 0x57, 0x57, 0,   0xFF, 0x57, 0xFF, 0,   0xFF, 0xFF, 0x57, 0,   0xFF, 0xFF, 0xFF, 0,
   /*  16 */	0,    0,    0, 0,   0x17, 0x17, 0x17, 0,   0x23, 0x23, 0x23, 0,   0x2F, 0x2F, 0x2F, 0,
   /*  20 */ 0x3B, 0x3B, 0x3B, 0,   0x47, 0x47, 0x47, 0,   0x53, 0x53, 0x53, 0,   0x63, 0x63, 0x63, 0,
   /*  24 */ 0x73, 0x73, 0x73, 0,   0x83, 0x83, 0x83, 0,   0x93, 0x93, 0x93, 0,   0xA3, 0xA3, 0xA3, 0,
   /*  28 */ 0xB7, 0xB7, 0xB7, 0,   0xCB, 0xCB, 0xCB, 0,   0xE3, 0xE3, 0xE3, 0,   0xFF, 0xFF, 0xFF, 0,
   /*  32 */	0,    0, 0xFF, 0,   0X43,    0, 0xFF, 0,   0x7F,    0, 0xFF, 0,   0xBF,    0, 0xFF, 0,
   /*  36 */ 0xFF,    0, 0xFF, 0,   0xFF,    0, 0xBF, 0,   0xFF,    0, 0x7F, 0,   0xFF,    0, 0x43, 0,
   /*  40 */ 0xFF,    0,    0, 0,   0xFF, 0x43,    0, 0,   0xFF, 0x7F,	  0, 0,   0xFF, 0xBF,	 0, 0,
   /*  44 */ 0xFF, 0xFF,    0, 0,   0xBF, 0xFF,    0, 0,   0x7F, 0xFF,	  0, 0,   0x43, 0xFF,	 0, 0,
   /*  48 */	0, 0xFF,    0, 0,      0, 0xFF, 0x43, 0,      0, 0xFF, 0x7F, 0,      0, 0xFF, 0xBF, 0,
   /*  52 */	0, 0xFF, 0xFF, 0,      0, 0xBF, 0xFF, 0,      0, 0x7F, 0xFF, 0,      0, 0x43, 0xFF, 0,
   /*  56 */ 0x7F, 0x7F, 0xFF, 0,   0x9F, 0x7F, 0xFF, 0,   0xBF, 0x7F, 0xFF, 0,   0xDF, 0x7F, 0xFF, 0,
   /*  60 */ 0xFF, 0x7F, 0xFF, 0,   0xFF, 0x7F, 0xDF, 0,   0xFF, 0x7F, 0xBF, 0,   0xFF, 0x7F, 0x9F, 0,
   /*  64 */ 0xFF, 0x7F, 0x7F, 0,   0xFF, 0x9F, 0x7F, 0,   0xFF, 0xBF, 0x7F, 0,   0xFF, 0xDF, 0x7F, 0,
   /*  68 */ 0xFF, 0xFF, 0x7F, 0,   0xDF, 0xFF, 0x7F, 0,   0xBF, 0xFF, 0x7F, 0,   0x9F, 0xFF, 0x7F, 0,
   /*  72 */ 0x7F, 0xFF, 0x7F, 0,   0x7F, 0xFF, 0x9F, 0,   0x7F, 0xFF, 0xBF, 0,   0x7F, 0xFF, 0xDF, 0,
   /*  76 */ 0x7F, 0xFF, 0xFF, 0,   0x7F, 0xDF, 0xFF, 0,   0x7F, 0xBF, 0xFF, 0,   0x7F, 0x9F, 0xFF, 0,
   /*  80 */ 0xB7, 0xB7, 0xFF, 0,   0xC7, 0xB7, 0xFF, 0,   0xDB, 0xB7, 0xFF, 0,   0xEB, 0xB7, 0xFF, 0,
   /*  84 */ 0xFF, 0xB7, 0xFF, 0,   0xFF, 0xB7, 0xEB, 0,   0xFF, 0xB7, 0xDB, 0,   0xFF, 0xB7, 0xC7, 0,
   /*  88 */ 0xFF, 0xB7, 0xB7, 0,   0xFF, 0xC7, 0xB7, 0,   0xFF, 0xDB, 0xB7, 0,   0xFF, 0xEB, 0xB7, 0,
   /*  92 */ 0xFF, 0xFF, 0xB7, 0,   0xEB, 0xFF, 0xB7, 0,   0xDB, 0xFF, 0xB7, 0,   0xC7, 0xFF, 0xB7, 0,
   /*  96 */ 0xB7, 0xFF, 0xB7, 0,   0xB7, 0xFF, 0xC7, 0,   0xB7, 0xFF, 0xDB, 0,   0xB7, 0xFF, 0xEB, 0,
   /* 100 */ 0xB7, 0xFF, 0xFF, 0,   0xB7, 0xEB, 0xFF, 0,   0xB7, 0xDB, 0xFF, 0,   0xB7, 0xC7, 0xFF, 0,
   /* 104 */	0,    0, 0x73, 0,   0x1F,    0, 0x73, 0,   0x3B,    0, 0x73, 0,   0x57,    0, 0x73, 0,
   /* 108 */ 0x73,    0, 0x73, 0,   0x73,    0, 0x57, 0,   0x73,    0, 0x3B, 0,   0x73,    0, 0x1F, 0,
   /* 112 */ 0x73,    0,    0, 0,   0x73, 0x1F,    0, 0,   0x73, 0x3B,	  0, 0,   0x73, 0x57,	 0, 0,
   /* 116 */ 0x73, 0x73,    0, 0,   0x57, 0x73,    0, 0,   0x3B, 0x73,	  0, 0,   0x1F, 0x73,	 0, 0,
   /* 120 */	0, 0x73,    0, 0,      0, 0x73, 0x1F, 0,      0, 0x73, 0x3B, 0,      0, 0x73, 0x57, 0,
   /* 124 */	0, 0x73, 0x73, 0,      0, 0x57, 0x73, 0,      0, 0x3B, 0x73, 0,      0, 0x1F, 0x73, 0,
   /* 128 */ 0x3B, 0x3B, 0x73, 0,   0x47, 0x3B, 0x73, 0,   0x57, 0x3B, 0x73, 0,   0x63, 0x3B, 0x73, 0,
   /* 132 */ 0x73, 0x3B, 0x73, 0,   0x73, 0x3B, 0x63, 0,   0x73, 0x3B, 0x57, 0,   0x73, 0x3B, 0x47, 0,
   /* 136 */ 0x73, 0x3B, 0x3B, 0,   0x73, 0x47, 0x3B, 0,   0x73, 0x57, 0x3B, 0,   0x73, 0x63, 0x3B, 0,
   /* 140 */ 0x73, 0x73, 0x3B, 0,   0x63, 0x73, 0x3B, 0,   0x57, 0x73, 0x3B, 0,   0x47, 0x73, 0x3B, 0,
   /* 144 */ 0x3B, 0x73, 0x3B, 0,   0x3B, 0x73, 0x47, 0,   0x3B, 0x73, 0x57, 0,   0x3B, 0x73, 0x63, 0,
   /* 148 */ 0x3B, 0x73, 0x73, 0,   0x3B, 0x63, 0x73, 0,   0x3B, 0x57, 0x73, 0,   0x3B, 0x47, 0x73, 0,
   /* 152 */ 0x53, 0x53, 0x73, 0,   0x5B, 0x53, 0x73, 0,   0x63, 0x53, 0x73, 0,   0x6B, 0x53, 0x73, 0,
   /* 156 */ 0x73, 0x53, 0x73, 0,   0x73, 0x53, 0x6B, 0,   0x73, 0x53, 0x63, 0,   0x73, 0x53, 0x5B, 0,
   /* 160 */ 0x73, 0x53, 0x53, 0,   0x73, 0x5B, 0x53, 0,   0x73, 0x63, 0x53, 0,   0x73, 0x6B, 0x53, 0,
   /* 164 */ 0x73, 0x73, 0x53, 0,   0x6B, 0x73, 0x53, 0,   0x63, 0x73, 0x53, 0,   0x5B, 0x73, 0x53, 0,
   /* 168 */ 0x53, 0x73, 0x53, 0,   0x53, 0x73, 0x5B, 0,   0x53, 0x73, 0x63, 0,   0x53, 0x73, 0x6B, 0,
   /* 172 */ 0x53, 0x73, 0x73, 0,   0x53, 0x6B, 0x73, 0,   0x53, 0x63, 0x73, 0,   0x53, 0x5B, 0x73, 0,
   /* 176 */	0,    0, 0x43, 0,   0x13,    0, 0x43, 0,   0x23,    0, 0x43, 0,   0x33,    0, 0x43, 0,
   /* 180 */ 0x43,    0, 0x43, 0,   0x43,    0, 0x33, 0,   0x43,    0, 0x23, 0,   0x43,    0, 0x13, 0,
   /* 184 */ 0x43,    0,    0, 0,   0x43, 0x13,    0, 0,   0x43, 0x23,	  0, 0,   0x43, 0x33,	 0, 0,
   /* 188 */ 0x43, 0x43,    0, 0,   0x33, 0x43,    0, 0,   0x23, 0x43,	  0, 0,   0x13, 0x43,	 0, 0,
   /* 192 */	0, 0x43,    0, 0,      0, 0x43, 0x13, 0,      0, 0x43, 0x23, 0,      0, 0x43, 0x33, 0,
   /* 196 */	0, 0x43, 0x43, 0,      0, 0x33, 0x43, 0,      0, 0x23, 0x43, 0,      0, 0x13, 0x43, 0,
   /* 200 */ 0x23, 0x23, 0x43, 0,   0x33, 0x23, 0x43, 0,   0x3B, 0x23, 0x43, 0,   0x33, 0x23, 0x43, 0,
   /* 204 */ 0x43, 0x23, 0x43, 0,   0x43, 0x23, 0x3B, 0,   0x43, 0x23, 0x33, 0,   0x43, 0x23, 0x33, 0,
   /* 208 */ 0x43, 0x23, 0x23, 0,   0x43, 0x33, 0x23, 0,   0x43, 0x33, 0x23, 0,   0x43, 0x3B, 0x23, 0,
   /* 212 */ 0x43, 0x43, 0x23, 0,   0x3B, 0x43, 0x23, 0,   0x33, 0x43, 0x23, 0,   0x33, 0x43, 0x23, 0,
   /* 216 */ 0x23, 0x43, 0x23, 0,   0x23, 0x43, 0x33, 0,   0x23, 0x43, 0x33, 0,   0x23, 0x43, 0x3B, 0,
   /* 220 */ 0x23, 0x43, 0x43, 0,   0x23, 0x3B, 0x43, 0,   0x23, 0x33, 0x43, 0,   0x23, 0x33, 0x43, 0,
   /* 224 */ 0x2F, 0x2F, 0x43, 0,   0x33, 0x2F, 0x43, 0,   0x37, 0x2F, 0x43, 0,   0x3F, 0x2F, 0x43, 0,
   /* 228 */ 0x43, 0x2F, 0x43, 0,   0x43, 0x2F, 0x3F, 0,   0x43, 0x2F, 0x37, 0,   0x43, 0x2F, 0x33, 0,
   /* 232 */ 0x43, 0x2F, 0x2F, 0,   0x43, 0x33, 0x2F, 0,   0x43, 0x37, 0x2F, 0,   0x43, 0x3F, 0x2F, 0,
   /* 236 */ 0x43, 0x43, 0x2F, 0,   0x3F, 0x43, 0x2F, 0,   0x37, 0x43, 0x2F, 0,   0x33, 0x43, 0x2F, 0,
   /* 240 */ 0x2F, 0x43, 0x2F, 0,   0x2F, 0x43, 0x33, 0,   0x2F, 0x43, 0x37, 0,   0x2F, 0x43, 0x3F, 0,
   /* 244 */ 0x2F, 0x43, 0x43, 0,   0x2F, 0x3F, 0x43, 0,   0x2F, 0x37, 0x43, 0,   0x2F, 0x33, 0x43, 0,
   /* 248 */	0,    0,    0, 0,      0,    0,    0, 0,      0,    0,	  0, 0,      0,    0,	 0, 0,
   /* 252 */	0,    0,    0, 0,      0,    0,    0, 0,      0,    0,	  0, 0,      0,    0,	 0, 0
     };

UINT  char_set[CHAR_NUM][CHAR_HEIGHT], // character set table
      mask[16] = {
		     0x8000, 0x4000, 0x2000, 0x1000,
		     0x0800, 0x0400, 0x0200, 0x0100,
		     0x0080, 0x0040, 0x0020, 0x0010,
		     0x0008, 0x0004, 0x0002, 0x0001
		 };

UINT	  system_option[OPT_NUM];// system option table

// ---------------------------------------------------------------------------
//		  addresses of I/O registers of Overlay Junior
// ---------------------------------------------------------------------------
UINT	  control_reg          =0x280, // 2X0 : control register
	  status_reg           =0x280, // 2X0 : status register
	  color_key_reg        =0x281, // 2X1 : color key register
	  card_id_reg          =0x282, // 2X2 : card ID register
	  crt_sel_reg          =0x283, // 2X3 : CRT select register
	  crt_data_reg         =0x284, // 2X4 : CRT data register
	  ramdac_addr_write_reg=0x285, // 2X5 : RAMDAC address write register
	  ramdac_addr_read_reg =0x286, // 2X6 : RAMDAC address read register
	  ramdac_data_reg      =0x287, // 2X7 : RAMDAC data register
	  ramdac_input_mask_reg=0x288; // 2X8 : RAMDAC input mask register

// ---------------------------------------------------------------------------
//		   values of I/O registers of Overlay Junior
// ---------------------------------------------------------------------------
BYTE	  control_reg_val          =0x20, // value of control register
	  status_reg_val           =0x61, // value of status register
	  color_key_reg_val        =0xfc, // value of color key register
	  card_id_reg_val          =0x0e, // value of card ID register
	  crt_sel_reg_val          =0xc0, // value of CRT select register
	  crt_data_reg_val         =0x64, // value of CRT data register
	  ramdac_addr_write_reg_val=0x00, // value of RAMDAC address write register
	  ramdac_addr_read_reg_val =0x00, // value of RAMDAC address read register
	  ramdac_input_mask_reg_val=0x00; // value of RAMDAC input mask register
ULONG	  ramdac_data_reg_val      =0L;	  // value of RAMDAC data register

CFGSTRUCT gConfig={0};          // structure of JUNIOR.INI file

WORD	  gwVideoWidth =640,    // width of video memory at current scan mode
	  gwVideoHeight=400,    // height of video memory at current scan mode
          /* Used in libinit.asm */
	  gwFrameBufSel=0,      // frame buffer selector(given by Windows)
	  gwNSelectors =1;      // no of selectors to allocate

// 10/18 Tang added
BYTE FAR  *glpVideoMemory=0;    // far pointer to address of video memory

BYTE	  gbInitial        =0,  // times of initialization
	  gbTVsystemType   =0,  // type of TV system(0:NTSC, 2:PAL)
	  gbMemReadMode    =0,  // read mode of video memory(ENABLE/DISABLE)
	  gbMemWriteMode   =0,  // write mode of video memory(ENABLE/DISABLE)
	  gfExtrnVideoExist=0;  // flag of external video exist

int       gwErrorCode=0;        // return error code of function

HANDLE	  ghMemory=0;
HANDLE	  hWnd, hInst, hdcInfo;

PALETTEENTRY  system_palette[256]={0};  // color values of system palette

unsigned long	gulEnterIntCount=0;

int  ynouse, yheight, sstart, gfScroll=FALSE;

/* array variable in function */
char          debugstr[200]={0};      //string for MessageBox
PALETTEENTRY  pe[MAXCOLORENTRY]={0};  //256 palette entries
UINT          xLength[2]={0};


// junisr.c
// global variable for handling scrolling
BOOL  gfHandleScroll   = FALSE;// flag to initinate ISR to start
BOOL  gfScrollStop     = TRUE; // flag indicate last page
BOOL  gfSwitch_PRG     = 0;    // flag to switch buffer in commander
BOOL  gfSwitch_ISR     = 0;    // flag to switch buffer in ISR
BYTE  gbScrollType[2]  = {0};  // 4 types of scrolling
int   gwRegTempStart[2]= {0};  // scoll register temp value
int   gwVramStart[2]   = {0};  // line to put image into
WORD  gwPageCount      = 1;    // count to load pages
WORD  gwRegGaps[2]     = {0};  // increments of register value
WORD  gwxShowWidth[2]  = {0};  // width of desired area
WORD  gwyShowHeight[2] = {0};  // height of desired area
WORD  gwxPageWidth[2]  = {0};  // width of a page
WORD  gwyPageHeight[2] = {0};  // height of a page
WORD  gwPadded[2]      = {0};  // padded no. to make a multiple of 2
WORD  gwPieceCount     = 0;    // lines to processed
BYTE huge *ghpBits[2]  = {0};  // huge pointer to image bits

BYTE  gbVertScanStart  = 0;    // vert. scan start value of reg.
BYTE  gbHorzScanStart  = 0;    // horz. scan start value of reg.
BOOL  gfPriIsrFinish   = TRUE; // flag of prior ISR execution
HANDLE  ghMem[2] = {0};        // global handle of memory

// 11/18/93 Tang added
//01/04/94 BOOL  gfStartScroll = FALSE;    // semaphore to isr to start scrolling

UINT  gwxVmemLeft      = 0;    // start x pos. in Video memory
UINT  gwyVmemTop       = 0;    // start y pos. in Video memory
UINT  gwxChangeLeft[2] = {0};
UINT  gwyChangeTop[2]  = {0};
UINT  gwxShowLeft[2]   = {0};
UINT  gwyShowTop[2]    = {0};

BOOL  gfBufferFull[2]  = {FALSE};
UINT  gwLineGaps[2]    = {0};
LPSTR      glpEmptyArray;       // pointer to an empty array
BYTE huge  *ghpBitsStart[2];    // huge pointer to image bits


/* 12/06/93 Tang added */
BYTE  gbBankType=1, gbDiagnose=0;

/* 12/22/93 Tang added */
BYTE  gbVideoMode=0;
WORD  gwImgWidthPad=0;
LPSTR	glpPageBuf;

//12/30
BYTE  gbPreMemSeg=9,gbPreBnkNo=9;

// 3/8/94 Tang added for PAL
WORD gwVertRegOffset;
